

<template>
  <view class="Mall4j container">
    <view class="news-detail">
      <view v-if="news.msgTitle" class="news-detail-title">{{ news.msgTitle }}</view>
      <view v-else class="news-detail-title">{{ news.title }}</view>
      <rich-text :nodes="news.content" />
    </view>
  </view>
</template>

<script>
var http = require('../../utils/http.js')
var util = require('../../utils/util.js')

export default {

  components: {},
  props: {},
  data() {
    return {
      news: {
        title: '',
        content: '',
        id: null
      }
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options)

    if (options.type == 'dist') {
      // 加载分销公告
      const params = {
        url: '/p/distribution/msg/info',
        method: 'GET',
        data: {
          msgId: options.id
        },
        callBack: res => {
          res.content = util.formatHtml(res.content)
          this.setData({
            news: res
          })
        }
      }
      http.request(params)
    } else {
      // 加载公告详情
      const params = {
        // `/shop/notice/info/${options.id}`
        url: '/shop/notice/info/' + options.id,
        method: 'GET',
        // data: {
        //   id: id,
        // },
        // callBack: function(news){
        callBack: res => {
          res.content = util.formatHtml(res.content)
          this.setData({
            news: res
          })
        }
      }
      http.request(params)
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {},
  methods: {}
}
</script>
<style>
@import "./news-detail.css";
</style>
